<!--
* description: 个人客户信息维护
* author: laimzh
* createdDate: 2019-08-14
-->
<template>
  <div class="app-container app-container-table">
    <crmGroupSubmit :formSubmitButton="formSubmitButton" />
    <el-form class="editPer filter-params-crm-scroll crm-s-scroll edit">
      <div class="filter-container-crm filter-title-crm">{{infoComponents[0].title}}</div>
      <div class="filter-container-crm filter-params-crm">
        <crmGroupForm
          :dynamicComponentss="infoComponents[0].tableComponents"
          :values="formField"
          ref="ref1"
        />
        <crmGroupForm :dynamicComponentss="infoComponents[1].tableComponents" :values="formField" />
        <crmGroupForm
          :dynamicComponentss="infoComponents[2].tableComponents"
          ref="upLoad"
          v-show="!(infoComponents[2].isShow==false)"
          :values="formField"
        />
      </div>
      <div class="filter-container-crm filter-title-crm">{{infoComponents[3].title}}</div>
      <div class="filter-container-crm filter-params-crm">
        <crmGroupForm
          :dynamicComponentss="infoComponents[3].tableComponents"
          :values="formField"
          ref="ref2"
        />
      </div>
      <div class="filter-container-crm filter-title-crm">{{infoComponents[4].title}}</div>
      <div class="filter-container-crm filter-params-crm">
        <crmGroupForm :dynamicComponentss="infoComponents[4].tableComponents" :values="formField" />
        <crmGroupForm :dynamicComponentss="infoComponents[5].tableComponents" :values="formField" />
        <crmGroupForm
          :dynamicComponentss="infoComponents[6].tableComponents"
          :values="formField"
          ref="interest"
        />
      </div>
    </el-form>
    <edit
      ref="keyInfo"
      :dynamicEditRowData="editRowData"
      :popupsVisible="editPopupsVisible"
      :key="editPopupsKey"
      :popupsState="editPopupsState"
      @close="close"
    ></edit>
  </div>
</template>
<script>
import { formMixins } from "@/components/mixins/formMixins";
import { crmApis } from "@/api/apiList/crm";
import { requestAPI } from "@/api/commonRequest";
export default {
  name: "editPer",
  // 组件混入对象
  mixins: [formMixins],
  components: {
    crmGroupForm: () =>
      import("@/components/crm/commonComponents/crmGroupForm"),
    crmGroupSubmit: () =>
      import("@/components/crm/commonComponents/crmGroupSubmit"),
    edit: () => import("@/views/crm/cu/badPhoneModifiEdit")
  },
  props: {},
  data() {
    return {
      State: "",
      keyInfo: false,
      ismore: false,
      ismutiple: false,
      action: "", //证件上传地址
      imgUrl: "",
      category: "crm",
      accepttype:
        ".jpg,.jpeg,.png,.gif,.bmp,.pdf,.JPG,.JPEG,.PBG,.GIF,.BMP,.PDF", //上传文件类型
      text1: "选择文件",
      limit: 1,
      showedit: false,
      params: {},
      nagflag: true,
      posflag: false,
      flag: true,
      editPopupsKey: "",
      editPopupsState: "",
      keyPopupsVisible: false,
      editRowData: {},
      infoComponents: [
        // 基本信息  0
        {
          title: "基本信息",
          tableComponents: [
            {
              compKey: "compKey1",
              labelName: "UID",
              codeField: "uid",
              isMust: true,
              readonly: true,
              disabled: true,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey2",
              labelName: "客户名称",
              codeField: "custName",
              isRequire: true,
              disabled: this.$route.params.status == "edit"&&
                this.$route.params.isCarowner == "是" ? true : false,
              isMust: true,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey3",
              labelName: "性别",
              codeField: "genderCode",
              isMul: false,
              lookuptype: "DB0022",
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey4",
              labelName: "出生日期",
              codeField: "birthDate",
              isRequire: false,
              isMust: true,
              inputType: "2",
              component: () => import("@/components/crm/Time/crmdatePicker")
            },
            {
              compKey: "compKey5",
              labelName: "民族",
              codeField: "nationCode",
              isRequire: false,
              isMust: true,
              isMul: false,
              lookuptype: "DB0026",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey6",
              labelName: "证件类型",
              codeField: "credTypeCode",
              lookuptype: "DB0037",
              isRequire: false,
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              isMust: true,
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey7",
              labelName: "证件号码",
              codeField: "credNo",
              isRequire: false,
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              isMust: true,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey10",
              labelName: "客户来源",
              codeField: "custOriginCode",
              lookuptype: "LX860",
              isRequire: false,
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              isMust: true,
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey8",
              labelName: "信息来源",
              codeField: "infoChanDCode",
              textField: "infoChanName",
              isMust: true,
              isMul: false,
              disabled:true,
              component: () =>
                import("@/components/crm/crmEjectWindows/crmSourceFrom/index"),
              type: "propus",
              emitCode: (rowData, _this) => this.changeSource(rowData, _this)
            },
            {
              compKey: "compKey9 ",
              labelName: "省份",
              codeField: "provinceId",
              textField: "provinceName",
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              isRequire:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? false
                  : true,
              isMust: true,
              isMul: false,
              lookuptype: crmApis.mdmOrgProvinceQueryFindAll,
              changeCode: this.changeCityByProvince,
              component: () =>
                import("@/components/crm/lookupValue/singleDropList")
            },
            {
              compKey: "provinceId",
              labelName: "城市",
              codeField: "cityId",
              textField: "cityName",
              isRequire:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? false
                  : true,
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              isMust: true,
              isMul: false,
              lookuptype: crmApis.mdmOrgCityQueryFindAll,
              changeCodeArray: [{ changCode: "provinceId" }],
              component: () =>
                import("@/components/crm/lookupValue/secondDropList")
            },
            {
              compKey: "cityId",
              labelName: "区县",
              codeField: "countyId",
              textField: "countyName",
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              isRequire: false,
              isMust: true,
              isMul: false,
              lookuptype: crmApis.mdmOrgCommunityQueryFindAll,
              changeCodeArray: [{ changCode: "cityId" }],
              component: () =>
                import("@/components/crm/lookupValue/secondDropList")
            }
          ]
        },
        // 1
        {
          tableComponents: [
            {
              compKey: "compKey12",
              labelName: "详细地址",
              codeField: "addrStreet", //addr  查询
              isRequire: false,
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              isMust: true,
              span: 12,
              component: () => import("@/components/crm/textbox/crmTextInput")
            }
          ]
        },
        // 2
        {
          title: "",
          isShow: true,
          tableComponents: [
            {
              compKey: "compKey13",
              labelName: "身份证1",
              codeField: "idCardPath",
              isMust: true,
              fileList: [],
              getVal: [],
              submitBtn: false,
              action: "/mp/file/crm/upload.do",
              limit: 1,
              accepttype: ".jpg,.png",
              isautoupload: true,
              component: () =>
                import("@/components/crm/crmEjectWindows/crmImgUpload/index"), //src\components\crm\crmEjectWindows\crmImgUpload\index.vue
              emitCode: this.getUploadFiles1
            },
            {
              compKey: "compKey14",
              labelName: "身份证2",
              codeField: "driveCardPath",
              submitBtn: false,
              isMust: true,
              fileList: [],
              getVal: [],
              action: "/mp/file/crm/upload.do",
              limit: 1,
              accepttype: ".jpg,.png",
              isautoupload: true,
              component: () =>
                import("@/components/crm/crmEjectWindows/crmImgUpload/index"),
              emitCode: this.getUploadFiles2
            },
            {
              compKey: "compKey15",
              labelName: "行驶证",
              codeField: "drivingCardPath",
              isMust: true,
              submitBtn: false,
              fileList: [],
              getVal: [],
              limit: 1,
              accepttype: ".jpg,.png",
              action: "/mp/file/crm/upload.do",
              isautoupload: true,
              isUpload: true,
              component: () =>
                import("@/components/crm/crmEjectWindows/crmImgUpload/index"),
              emitCode: this.getUploadFiles3
            }
            // {
            //   compKey: "compKey13",
            //   labelName: "身份证",
            //   codeField: "idCardPath", //身份证路径
            //   isMust: true,
            //   fileList: [],
            //   getVal: [],
            //   limit:1,
            //   buttonText: "选择文件1",
            //   action: "/mp/file/crm/upload.do",
            //   isautoupload: true,
            //   accepttype: ".jpg,.png",
            //   limit: 1,
            //   component: () => import("@/components/crm/EjectWindows/UpLoad"),
            //   emitCode: this.getUploadFiles1,
            //   delFiles:this.getRemovedFiles1
            // },
            // {
            //   compKey: "compKey14",
            //   labelName: "驾驶证",
            //   codeField: "driveCardPath", //驾驶证路径
            //   isMust: true,
            //   fileList: [],
            //   getVal: [],
            //   limit:1,
            //   buttonText: "选择文件2",
            //   action: "/mp/file/crm/upload.do",
            //   accepttype: ".jpg,.png",
            //   limit: 1,
            //   component: () => import("@/components/crm/EjectWindows/UpLoad"),
            //   emitCode: this.getUploadFiles2,
            //   delFiles:this.getRemovedFiles2
            // },
            // {
            //   compKey: "compKey15",
            //   labelName: "行驶证",
            //   codeField: "drivingCardPath", //行驶证路径
            //   isMust: true,
            //   fileList: [],
            //   getVal: [],
            //   limit:1,
            //   buttonText: "选择文件3",
            //   action: "/mp/file/crm/upload.do",
            //   isautoupload: true,
            //   accepttype: ".jpg,.png",
            //   limit: 1,
            //   component: () => import("@/components/crm/EjectWindows/UpLoad"),
            //   emitCode: this.getUploadFiles3,
            //   delFiles:this.getRemovedFiles3
            // }
          ]
        },
        // 联系信息  3
        {
          title: "联系信息",
          tableComponents: [
            {
              compKey: "compKey18",
              labelName: "电话",
              codeField: "phone",
              isRequire: true,
              validrule: {
                noRequire: false,
                isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
              },
              disabled:
                this.$route.params.status == "edit" &&
                this.$route.params.isCarowner == "是"
                  ? true
                  : false,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey19",
              labelName: "备用电话",
              codeField: "backupPhone",
              isRequire: true,
              validrule: {
                noRequire: true,
                isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
              },
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey20",
              labelName: "家庭电话",
              codeField: "homeTel",
              isRequire: true,
              validrule: {
                noRequire: true,
                isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
              },
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey21",
              labelName: "办公电话",
              codeField: "officeTel",
              isRequire: true,
              validrule: {
                noRequire: true,
                isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
              },
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey22",
              labelName: "QQ号",
              codeField: "qq",
              isRequire: true,
              validrule: {
                noRequire: true,
                isformat: /[1-9][0-9]{4,14}/
              },
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey23",
              labelName: "微信号",
              codeField: "openId",
              isRequire: true,
              validrule: {
                noRequire: true,
                isformat: /^[a-zA-Z\d_]{5,}$/
              },
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey25",
              labelName: "邮政编码",
              codeField: "addrZip",
              isRequire: true,
              validrule: {
                noRequire: true,
                isformat: /[1-9]\d{5}(?!\d)/
              },
              isMust: true,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey24",
              labelName: "电子邮箱",
              codeField: "email",
              isRequire: true,
              validrule: {
                noRequire: true,
                isformat: /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/
              },
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            // {
            //   compKey: "compKey25",
            //   labelName: "方便联系场所",
            //   codeField: "convLocaleCode",
            //   isMul: false,
            //   lookuptype: "DB0016",
            //   component: () =>
            //     import("@/components/crm/lookupValue/lookupvalue")
            // },
            {
              compKey: "compKey26",
              labelName: "方便联系时段",
              codeField: "convTimeCode",
              isMul: false,
              lookuptype: "DB0030",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey27",
              labelName: "首选联系方式",
              codeField: "contactTypeCode",
              isMul: false,
              lookuptype: "DB0029",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            }
          ]
        },
        // 客户画像  4
        {
          title: "客户画像",
          tableComponents: [
            {
              compKey: "compKey28",
              labelName: "学历",
              codeField: "degreeCode",
              isMul: false,
              lookuptype: "DB0044",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey29",
              labelName: "行业",
              codeField: "tradeCode",
              isMul: false,
              lookuptype: "VE0480",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey30",
              labelName: "公司全称",
              codeField: "compName",
              isMul: false,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey31",
              labelName: "职业",
              codeField: "jobCode",
              isMust: true,
              isMul: false,
              lookuptype: "DB0031",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey33",
              labelName: "婚姻状况",
              codeField: "marriagedCode",
              isMul: false,
              lookuptype: "VE0502",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey34",
              labelName: "是否有子女",
              codeField: "isHaveChildCode", //isHaveChildCode
              isMul: false,
              lookuptype: "DB0064",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey35",
              labelName: "家庭年收入",
              codeField: "familyIncomeCode",
              isMul: false,
              lookuptype: "DB0028",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey36",
              labelName: "已有车型",
              codeField: "holdCarTypeCode",
              textField: "holdCarTypeName",
              isRequire: false,
              isMust: true,
              isMul: false,
              lookuptype: crmApis.mdmHoldCarTypeQueryFindAll,
              component: () =>
                import("@/components/crm/lookupValue/apiDropList")
            },
            {
              compKey: "compKey37",
              labelName: "车辆拥有时间",
              codeField: "holdCarTimeCode",
              textField: "holdCarTimeName",
              isMul: false,
              lookuptype: "LX818",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey38",
              labelName: "是否有驾驶证",
              codeField: "haveDriverCred",
              isMul: false,
              lookuptype: "DB0064",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey39",
              labelName: "驾照类型",
              codeField: "driverTypeCode",
              textField: "driverTypeName",
              isMul: false,
              lookuptype: crmApis.mdmDriverTypeQueryFindAll,
              component: () =>
                import("@/components/crm/lookupValue/apiDropList")
            },
            {
              compKey: "compKey40",
              labelName: "驾龄",
              codeField: "driverTimeCode",
              isMul: false,
              lookuptype: "DB0042",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey41",
              labelName: "付款方式",
              codeField: "buyTypeCode",
              textField: "buyTypeName",
              isMul: false,
              lookuptype: "VE0117",
              disabled: true,
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            {
              compKey: "compKey42",
              labelName: "意向车型",
              codeField: "inteCarTypeCode",
              textField: "inteCarTypeName",
              readonly: true,
              disabled: true,
              isMul: false,
              component: () =>
                import("@/components/crm/crmEjectWindows/crmCartype/index")
            },
            {
              compKey: "compKey43",
              labelName: "意向价格",
              codeField: "buyBudget",
              textField: "buyBudgetName",
              isMul: false,
              readonly: true,
              disabled: true,
              lookuptype: "APPVE9527_09",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            },
            // {
            //   compKey: "compKey44",
            //   labelName: "意向外观颜色",
            //   codeField: "intentCarColor",
            //   textField: "carColorName",
            //   isMul: false,
            //   readonly: true,
            //   disabled: true,
            //   lookuptype: crmApis.mdmCarTypeColorQueryGroupBySeriesId,
            //   component: () =>
            //     import("@/components/crm/lookupValue/apiDropList")
            // },
            // {
            //   compKey: "compKey45",
            //   labelName: "意向内饰色",
            //   codeField: "intentCarInnerColor",
            //   textField: "carIncolorName",
            //   isMul: false,
            //   readonly: true,
            //   disabled: true,
            //   lookuptype: crmApis.mdmCarTypeIncolorQueryGroupBySeriesId,
            //   component: () =>
            //     import("@/components/crm/lookupValue/apiDropList")
            // },
            {
              compKey: "compKey50",
              labelName: "意向外观颜色",
              codeField: "carColorName",
              disabled: true,
              isMust: true,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            {
              compKey: "compKey51",
              labelName: "意向内饰色",
              codeField: "carIncolorName",
              disabled: true,
              isMust: true,
              component: () => import("@/components/crm/textbox/crmTextInput")
            },
            // {
            //   compKey: "compKey47",
            //   labelName: "是否网点VIP",
            //   codeField: "isVip",
            //   isMul: false,
            //   lookuptype: "DB0064",
            //   component: () =>
            //     import("@/components/crm/lookupValue/lookupvalue")
            // },
            // {
            //   compKey: "compKey48",
            //   labelName: "VIP等级",
            //   codeField: "vipLevel",
            //   isMul: false,
            //   lookuptype: "LX817",
            //   component: () =>
            //     import("@/components/crm/lookupValue/lookupvalue")
            // },
            {
              compKey: "compKey49",
              labelName: "上牌指标",
              codeField: "isHaveCarnum",
              isMul: false,
              lookuptype: "DB0064",
              component: () =>
                import("@/components/crm/lookupValue/lookupvalue")
            }
          ]
        },
        // 5
        {
          tableComponents: [
            {
              compKey: "compKey450",
              labelName: "客户标签",
              // getVal: "hh",
              codeField: "custTag",
              // changeCode: val => this.getTags(val),
              component: () => import("@/views/crm/cu/CustInfo/tags")
            }
          ]
        },
        // 6
        {
          tableComponents: [
            {
              compKey: "compKey46",
              labelName: "关注点",
              lookuptype: "APPVE9527_07",
              codeField: "custFocus",
              isMul: false,
              component: () => import("@/views/crm/cu/CustInfo/interest")
            },
            {
              compKey: "compKey51",
              labelName: "兴趣爱好",
              codeField: "hobby",
              getVal: "",
              component: () => import("@/views/crm/cu/CustInfo/interest")
            }
          ]
        }
      ],
      isdisplay: {
        ismuti: false
      },
      credit: false,
      // 保存API配置对象
      apiConfig: crmApis.createdOneIdMutationSaveCust, //客户信息-修改客户信息
      formSubmitButton: [
        // {
        //   compKey: "buttonKey1",
        //   text: "修改关键信息",
        //   size: "small",
        //   type: "",
        //   clickEvent: () => this.edit(),
        //   isShow:
        //     this.$route.params.status == "edit" &&
        //     this.$route.params.isCarowner == "是"
        //       ? true
        //       : false
        // },
        {
          compKey: "buttonKey2",
          text: "保存",
          size: "small",
          type: "",
          clickEvent: () => this.save(),
          isShow: true
        }
        // {
        //   compKey: "buttonKey3",
        //   text: "测试",
        //   size: "small",
        //   type: "",
        //   clickEvent: () => this.test(),
        //   isShow: true
        // }
      ],
      // 标题
      textMap: {
        edit: "维护个人客户",
        add: "新建个人客户"
      },
      formField: {
        // phonee:"",
        custOriginCode: "", //客户来源
        custSourceName: "",
        custTag: "", //客户标签
        uid: "",
        custName: "",
        custFullName: "",
        genderCode: "",
        birthDate: "",
        provinceId: "",
        addrProvince: "",
        provinceName: "",
        cityId: "",
        addrCity: "",
        cityName: "",
        countyId: "",
        countyName: "",
        addrCounty: "",
        addrStreet: "",
        postCode: "",

        nationCode: "",
        jobCode: "",
        credTypeCode: "",
        credTypeName: "",
        credNo: "",
        addrStreet: "", //详细地址
        hobby: "",
        phone: "",
        backupPhone: "",
        homeTel: "",
        officeTel: "",
        qq: "",
        openId: "",
        webchat: "",
        email: "",
        convTimeCode: "",
        contactTypeCode: "",
        familyIncomeCode: "",
        degreeCode: "",
        isVip: "",
        // focuseNameList: "",
        // custPropertyName: "",
        marriagedCode: "",
        // isHaveChild: "",
        isHaveChildCode: "",
        custNo: "",
        dlrCustNo: "",
        convLocaleCode: "", //最佳联系场所
        tradeCode: "",
        driverTimeCode: "",
        holdCarTimeCode: "",

        // interestsNameList: ""
        contactTypeName: "",
        convTimeName: "",
        convLocaleName: "",
        addrZip: "",
        // invAccount: "",
        // invBank: "",
        invBankName: "",
        holdCarTypeCode: "",
        haveDriverCred: "",
        haveDriverCredName: "",
        driverTypeCode: "",
        driverTypeName: "",
        inteCarTypeCode: "",
        inteCarTypeName: "",
        buyBudget: "",
        buyBudgetName: "",
        intentCarColor: "",
        carColorName: "",
        intentCarInnerColor: "",
        carIncolorName: "",
        buyTypeCode: "",
        buyTypeName: "",
        isHaveCarnum: "",
        isHaveCarnumName: "",
        compName: "",
        vipLevel: "",
        custFocus: "",
        custClassCode: "0",
        infoChanMCode:"",
        cantactWayCode:"",
        infoChanDCode:"",
        infoChanName:"",
      },
      saveformField: {
        dlrCustNo: "",
        uid: "",
        custFullName: "",
        custName: "",
        genderCode: "",
        birthDate: "",
        nationCode: "",
        credTypeCode: "",
        credNo: "",
        custOriginCode: "",
        infoChanDCode:"",
        provinceId: "",
        addrProvince: "",
        cityId: "",
        addrCity: "",
        countyId: "",
        addrCounty: "",
        addrStreet: "",
        phone: "",
        backupPhone: "",
        homeTel: "",
        officeTel: "",
        webchat: "",
        qq: "",
        addrZip: "",
        email: "",
        convLocaleCode: "",
        convTimeCode: "",
        contactTypeCode: "",
        degreeCode: "",
        tradeCode: "",
        compName: "",
        jobCode: "",
        marriagedCode: "",
        isHaveChild: "",
        familyIncomeCode: "",
        holdCarTypeCode: "",
        holdCarTimeCode: "",
        haveDriverCred: "",
        driverTypeCode: "",
        driverTimeCode: "",
        custFocus: "",
        isVip: "",
        vipLevel: "",
        isHaveCarnum: "",
        custTag: "",
        hobby: "",
        infoChanMCode:"",
      },
      vin: "",
      bcStatus: this.$route.params.status,
      bczz: Object,
      baCustId: "",
      dlrCustNo: this.$route.params.dlrCustNo,
      idCardPath: "null",
      driveCardPath: "null",
      drivingCardPath: "null"
    };
  },
  mounted() {
    this.$nextTick(() => {
      if (this.$route.params.hZZ != undefined) {
        this.bczz = this.$route.params.hZZ;
      }
      this.initdata();
    });
  },
  methods: {
    //信息来源change
    changeSource(rowData, _this) {
      let results = rowData[0];
      this.formField.infoChanDCode = results.infoChanDCode;
      this.formField.infoChanMCode = results.infoChanMCode;
    },
    test() {
      this.uploadFiles("1", this.idCardPath);
    },
    // 获取客户标签
    // getTags(val) {
    //   this.formField.custTag = val;
    // },
    manage() {
      this.credit = true;
    },
    // 关键信息修改
    edit(index) {
      this.editRowData = this.formField;
      this.editRowData.vin = this.vin;
      this.editPopupsState = "edit";
      this.editPopupsVisible = true;
      this.editPopupsKey = this.$utils.generateId();
      //this.showEdit("edit");
    },
    showEdit(type) {
      this.editPopupsState = type;
      this.keyPopupsVisible = true;
      if (this.resetDialogKey === true) {
        this.editPopupsKey = this.$utils.generateId();
      }
    },
    // 查询
    query(api, row, params, num) {
      let that = this;
      let queryObj = {
        type: "query",
        apiConfig: api,
        apiServices: [
          {
            apiQueryRow: row
          }
        ],
        variables: {
          dataInfo: params
        }
      };
      var paramD = that.$getParams(queryObj);
      requestAPI(paramD).then(response => {
        if (response.data[queryObj.apiConfig.ServiceCode].result == "1") {
          let results = response.data[queryObj.apiConfig.ServiceCode].rows[0];
          for (let key in this.formField) {
            if (results.hasOwnProperty(key)) {
              this.formField[key] = results[key];
            }
            debugger;
            if (
              key === "birthDate" &&
              results.hasOwnProperty(key) &&
              results[key]
            ) {
              this.formField[key] = results[key] + " 00:00:00";
            }
          }
          let list1 = [];
          let list2 = [];
          let list3 = [];
          list1[0] = {};
          list2[0] = {};
          list3[0] = {};
          if (num == 1) {
            // debugger
            if (results.idCardPath && results.idCardPath != "null") {
              list1[0].name = results.idCardPath.split("/")[
                results.idCardPath.split("/").length - 1
              ];
              list1[0].url = results.idCardPath;
              that.idCardPath = results.idCardPath;
              that.infoComponents[2].tableComponents[0].getVal = list1;
            }
            if (results.driveCardPath && results.driveCardPath != "null") {
              list2[0].name = results.driveCardPath.split("/")[
                results.driveCardPath.split("/").length - 1
              ];
              list2[0].url = results.driveCardPath;
              that.driveCardPath = results.driveCardPath;
              that.infoComponents[2].tableComponents[1].getVal = list2;
            }
            if (results.drivingCardPath && results.drivingCardPath != "null") {
              list3[0].name = results.drivingCardPath.split("/")[
                results.drivingCardPath.split("/").length - 1
              ];
              list3[0].url = results.drivingCardPath;
              that.drivingCardPath = results.drivingCardPath;
              that.infoComponents[2].tableComponents[2].getVal = list3;
            }
          } else {
            this.formField.provinceName = this.formField.addrProvince;
            this.formField.cityName = this.formField.addrCity;
            this.formField.countyName = this.formField.addrCounty;
          }
        } else {
          that.$crmcf.showMessages(
            that,
            "error",
            response.data[queryObj.apiConfig.ServiceCode].msg
          );
        }
      });
    },
    initdata() {
      let that = this;
      if (this.$route.params.status == "edit") {
        this.vin = this.$route.params.vin;
        let params = {};
        // params.custNo = this.$route.params.custNo;
        params.dlrCustNo = this.$route.params.dlrCustNo;
        that.baCustId = this.$route.params.dlrCustNo;
        // 基本信息
        let formField1 = [
          "uid",
          "custName",
          "custFullName",
          "genderCode",
          "birthDate",
          "provinceId",
          "cityId",
          "countyId",
          "addrProvince",
          "addrCity",
          "addrCounty",
          "nationCode",
          "dlrCustNo",
          "credTypeCode",
          "credNo",
          "addrStreet",
          "custOriginCode",
          "custSourceName",
          "infoChanDCode",
          "infoChanName",
          "idCardPath",
          "driveCardPath",
          "drivingCardPath",
          "infoChanMCode",
          "cantactWayCode"
        ];
        this.query(
          crmApis.custViewCustBaseInfoQueryFindAll,
          formField1,
          params,
          1
        );
        // 联系信息
        let formField2 = [
          "addrZip",
          "phone",
          "backupPhone",
          "homeTel",
          "officeTel",
          "qq",
          "openId",
          "email",
          "convTimeCode",
          "convTimeName",
          "contactTypeCode",
          "contactTypeName",
          "invBank",
          "invBankName",
          "convLocaleCode",
          "convLocaleName"
        ];
        this.query(crmApis.custViewContactWayQueryFindAll, formField2, params);
        // this.formField.phone=this.formField.phonee

        // 客户画像
        let queryObj = {
          type: "query",
          apiConfig: crmApis.custViewCustChannelImageQueryFindAll,
          apiServices: [
            {
              apiQueryRow: [
                "cantactWayName",
                "infoChanMName",
                "infoChanDName",
                "familyIncomeCode",
                "familyIncomeName",
                "degreeCode",
                "degreeName",
                "tradeName",
                "tradeCode", //行业
                "compName",
                "jobCode",
                "jobName",
                "driverTimeName", //驾龄
                "driverTimeCode",
                "marriagedCode",
                "marriagedName",
                "isVip",
                "isVipName",
                "vipLevel",
                "vipLevelName",
                "isHaveChildName",
                "isHaveCarnum",
                "isHaveCarnumName", //上牌指标
                "holdCarTypeName",
                "holdCarTypeCode",
                "holdCarTimeName",
                "carSeriesCn", //职务
                "hobby",
                "custFocus",
                "custTag",
                "holdCarTimeCode",
                // "isHaveChild",
                "isHaveChildCode",
                "haveDriverCred", //是否有驾驶证
                "haveDriverCredName",
                "driverTypeName",
                "driverTypeCode",
                "inteCarTypeCode",
                "inteCarTypeName",
                "buyBudget",
                "buyBudgetName",
                "carColorName",
                "intentCarInnerColor",
                "carIncolorName",
                "buyTypeCode",
                "buyTypeName",
                "isHaveCarnum",
                "isHaveCarnumName"
                // "inteCarTypeName"
              ]
            }
          ],
          variables: {
            dataInfo: params
          }
        };
        var paramD = that.$getParams(queryObj);
        requestAPI(paramD).then(response => {
          if (response.data[queryObj.apiConfig.ServiceCode].result == "1") {
            let results = response.data[queryObj.apiConfig.ServiceCode].rows[0];
            for (let key in this.formField) {
              if (results.hasOwnProperty(key)) {
                this.formField[key] = results[key];
              }
            }
            this.infoComponents[5].tableComponents[0].getVal = results.custTag;
          } else {
            that.$crmcf.showMessages(
              that,
              "error",
              response.data[queryObj.apiConfig.ServiceCode].msg
            );
          }
        });
      }
      if (this.$route.params.isCarowner == "是") {
        this.infoComponents[2].isShow = true;
      } else {
        this.infoComponents[2].isShow = false;
      }
    },
    //保存
    save() {
      // validpopup  弹窗  validpage 页面
      //this.$utils.validataMoth(this, "validpage");
      let that = this;
      that.$utils.validataMoth(that, "crmpage", "", "ref2");
      that.$utils.validataMoth(that, "crmpage", "", "ref1");
      // this.$refs.upLoad.$refs.compKey13[0].submitUpload();
      // this.$refs.upLoad.$refs.compKey14[0].submitUpload();
      // this.$refs.upLoad.$refs.compKey15[0].submitUpload();
      let vaild = true;
      let vaildParams = {
        phone: [
          "telOrphone",
          that.formField.phone,
          `<div>请输入正确的手机或电话号码！</div>`
        ],
        custName: [
          "simpleName",
          that.formField.custName,
          `<div>请输入中文姓名在2-20个字之间</div>`
        ],
        birthDate: [
          "date",
          that.formField.birthDate,
          "<div>请输入正确的出生日期</div>"
        ],
        // credNo: [
        //   "idCard",
        //   that.formField.credNo,
        //   "<div>请输入18位证件号</div>"
        // ],
        addrStreet: [
          "addr",
          that.formField.addrStreet,
          "<div>请输入正确的国内地址</div>"
        ],
        backupPhone: [
          "telOrphone",
          that.formField.backupPhone,
          "<div>请输入正确的手机或电话号码！</div>"
        ],
        homeTel: [
          "telOrphone",
          that.formField.homeTel,
          "<div>请输入正确的手机或电话号码！</div>"
        ],
        officeTel: [
          "telOrphone",
          that.formField.officeTel,
          "<div>请输入正确的手机或电话号码！</div>"
        ],
        qq: ["QQ", that.formField.qq, "<div>请输入4到14位数字的QQ号码</div>"],
        openId: [
          "weChat",
          that.formField.openId,
          "<div>请输入5位以上，数字或字母或下划线组成的微信号</div>"
        ],
        addrZip: [
          "zip",
          that.formField.addrZip,
          "<div>请输入6位数字的邮政编码</div>"
        ],
        email: [
          "email",
          that.formField.email,
          "<div>请输入格式正确的电子邮箱</div>"
        ],
        compName: [
          "chinese",
          that.formField.compName,
          "<div>公司全称不能超过50个字</div>"
        ]
      };
      // vaild = this.$crmcf.regex(that, vaildParams);
      // if (that.formField.phone == "" || that.formField.phone == null) {
      //   this.$notify.error({
      //     title: "校验项",
      //     message: "请输入正确的手机或电话号码！"
      //   });
      //   vaild = false;
      // }
      // if (that.formField.custName == "" || that.formField.custName == null) {
      //   this.$notify.error({
      //     title: "校验项",
      //     message: "请输入中文姓名且不超过10个字"
      //   });
      //   vaild = false;
      // }
      var html = "";
      let reg = that.$crmcf.crmRegExp("name");
      let reg1 = that.$crmcf.crmRegExp("tel");
      let reg2 = that.$crmcf.crmRegExp("telOrphone");
      let reg3 = that.$crmcf.crmRegExp("chnAndEn");
      let reg4 = that.$crmcf.crmRegExp("zip");
      let reg5 = that.$crmcf.crmRegExp("idCard");
      let reg6 = that.$crmcf.crmRegExp("email");
      let reg7 = that.$crmcf.crmRegExp("weChat");
      let reg8 = that.$crmcf.crmRegExp("QQ");
      if (!that.formField.custName) {
        html = html + `<div class="sys-alertDiv">请输入客户名称</div>`;
      } else {
        var temp = 0;
        for (var i = 0; i < that.formField.custName.length; i++) {
          if (/[\u4e00-\u9fa5]/.test(that.formField.custName[i])) {
            temp += 2;
          } else {
            temp++;
          }
        }
        if (temp > 50) {
          html =
            html + `<div class="sys-alertDiv">客户名称不能超过50个字符</div>`;
        }
      }
      if (
        that.formField.credTypeCode == "1" &&
        that.formField.credNo != "" &&
        that.formField.credNo != null
      ) {
        if (!reg5.test(that.formField.credNo)) {
          html = html + `<div class="sys-alertDiv">请输入18位证件号</div>`;
        }
      }
      if (
        that.$route.params.status == "edit" &&
        that.$route.params.isCarowner == "是"
      ) {
      } else {
        if (!that.formField.provinceId) {
          html = html + `<div class="sys-alertDiv">请选择省份</div>`;
        }
        if (!that.formField.cityId) {
          html = html + `<div class="sys-alertDiv">请选择城市</div>`;
        }
      }
      if (!that.formField.phone) {
        html = html + `<div class="sys-alertDiv">请输入电话</div>`;
      } else {
        if (!reg2.test(that.formField.phone)) {
          html =
            html +
            `<div class="sys-alertDiv">电话（手机或座机号码）格式不正确</div>`;
        }
      }
      if (that.formField.backupPhone) {
        if (!reg2.test(that.formField.backupPhone)) {
          html =
            html +
            `<div class="sys-alertDiv">备用电话（手机或座机号码）格式不正确</div>`;
        }
      }
      if (that.formField.homeTel) {
        if (!reg2.test(that.formField.homeTel)) {
          html =
            html +
            `<div class="sys-alertDiv">家庭电话（手机或座机号码）格式不正确</div>`;
        }
      }
      if (that.formField.officeTel) {
        if (!reg2.test(that.formField.officeTel)) {
          html =
            html +
            `<div class="sys-alertDiv">办公电话（手机或座机号码）格式不正确</div>`;
        }
      }
      if (that.formField.qq) {
        if (!reg8.test(that.formField.qq)) {
          html =
            html + `<div class="sys-alertDiv">请输入4到14位数字的QQ号码</div>`;
        }
      }
      if (that.formField.openId) {
        if (!reg7.test(that.formField.openId)) {
          html =
            html +
            `<div class="sys-alertDiv">请输入5位以上，数字或字母或下划线组成的微信号</div>`;
        }
      }
      if (that.formField.addrZip) {
        if (!reg4.test(that.formField.addrZip)) {
          html = html + `<div class="sys-alertDiv">邮政编码格式不正确</div>`;
        }
      }
      if (that.formField.email) {
        if (!reg6.test(that.formField.email)) {
          html = html + `<div class="sys-alertDiv">电子邮箱格式不正确</div>`;
        }
      }
      if (that.formField.compName) {
        var temp = 0;
        for (var i = 0; i < that.formField.compName.length; i++) {
          if (/[\u4e00-\u9fa5]/.test(that.formField.compName[i])) {
            temp += 2;
          } else {
            temp++;
          }
        }
        if (temp > 50) {
          html =
            html + `<div class="sys-alertDiv">公司全称不能超过50个字符</div>`;
        }
      }
      if (html != "") {
        // this.$notify.error({
        //   title: "校验项",
        //   dangerouslyUseHTMLString: true,
        //   message: html
        // });
        this.$crmcf.showMessages(this, "error", html, true);
        return;
      }
      if (vaild) {
        this.saveForm();
      }
    },
    saveForm() {
      //保存表单
      let that = this;
      // that.handleChange(param);

      this.formField.custFullName = this.formField.custName;
      let results = this.formField;
      for (let key in this.saveformField) {
        if (results.hasOwnProperty(key)) {
          this.saveformField[key] = results[key];
        }
      }
      debugger;
      this.saveformField.dlrCustNo = this.baCustId;
      this.saveformField.addrProvince = this.formField.provinceName;
      this.saveformField.addrCity = this.formField.cityName;
      this.saveformField.addrCounty = this.formField.countyName;
      this.saveformField.custClassCode = "0";
      this.saveformField.isHaveChild = this.formField.isHaveChildCode;
      this.saveformField.webchat = this.formField.openId;
      // this.saveformField.custSourceCode='XL008'

      let custModifyScence = "";
      if (this.bcStatus == "edit") {
        custModifyScence = "303";
      } else if (this.bcStatus == "add") {
        custModifyScence = "301";
      }
      let queryObj = {
        // api配置
        type: "mutation",
        apiConfig: crmApis.createdOneIdMutationSaveCust, //客户信息-修改
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: {
            custModifyScence: custModifyScence, //场景编码--修改客户信息
            custInfo: this.saveformField
          }
        }
      };

      //转换了中台请求格式数据
      var paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestAPI(paramD).then(response => {
        if (
          response.data[queryObj.apiConfig.ServiceCode].result == "1"
          // &&response.data[queryObj.apiConfig.ServiceCode].rows != ""
        ) {
          that.uploadFiles("1", that.idCardPath);
          that.uploadFiles("2", that.driveCardPath);
          that.uploadFiles("3", that.drivingCardPath);
          that.$crmcf.showMessages(that, "success", "保存成功！");
          that.$crmcf.crmcloseView(that);
          that.bczz.$refs.multipleTable.queryTable();
        } else {
          that.$crmcf.showMessages(
            that,
            "error",
            response.data[queryObj.apiConfig.ServiceCode].msg
          );
        }
      });
    },
    //附件上传成功回调
    getUploadFiles1(list) {
      if (list.length > 0) {
        for (var i = 0; i < list.length; i++) {
          this.idCardPath = list[i].path;
        }
      } else {
        this.idCardPath = "";
      }
    },
    getUploadFiles2(list) {
      if (list.length > 0) {
        for (var i = 0; i < list.length; i++) {
          this.driveCardPath = list[i].path;
        }
      } else {
        this.driveCardPath = "";
      }
    },
    getUploadFiles3(list) {
      debugger;
      if (list.length > 0) {
        for (var i = 0; i < list.length; i++) {
          this.drivingCardPath = list[i].path;
        }
      } else {
        this.drivingCardPath = "";
      }
    },
    //移除文件列表
    getRemovedFiles1(list) {
      this.idCardPath = "null";
    },
    getRemovedFiles2(list) {
      this.driveCardPath = "null";
    },
    getRemovedFiles3(list) {
      this.drivingCardPath = "null";
    },
    //附件上传
    uploadFiles(type, path) {
      let that = this;
      let queryObj = {
        // api配置
        type: "mutation",
        apiConfig: crmApis.mdmDlrCustInfoMutationUploadImg,
        // 需要调用的API服务配置
        apiServices: [
          {
            //表格中台返回网格的字段
            apiQueryRow: []
          }
        ],
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: {
            dlrCustNo: that.dlrCustNo,
            idCardPath: path,
            credTypeCode: type
          }
        }
      };
      //转换了中台请求格式数据
      var paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestAPI(paramD).then(response => {
        if (
          response.data[queryObj.apiConfig.ServiceCode].result === "1"
          //&&response.data[queryObj.apiConfig.ServiceCode].rows!=""
        ) {
        } else {
          // that.$crmcf.showMessages(that,'error',response.data[queryObj.apiConfig.ServiceCode].msg)
        }
      });
    }
    /**
     * 上传请求封装
     *
     */
    // handleChange(param) {
    //   debugger
    //   const that = this;
    //   // MP上传url
    //   const url = "/mp/file/" + that.category + "/upload.do";
    //   that
    //     .$requestUpload(url, param)
    //     .then(response => {
    //       that.imgUrl = "";
    //       let code = "";
    //       let text = "";
    //       if (
    //         response.result === "1" &&
    //         response.path.length > 0 &&
    //         response.path[0].length > 0 &&
    //         response.path[0][0].indexOf("|") > -1
    //       ) {

    //         // 返回格式：[["xxxx.png|/upload/{category}/{yyyyMMdd}/{guid}/xxxx.jpg","xxx.xx KB"]]
    //         // 截取出/upload/{category}/{yyyyMMdd}/{guid}/xxxx.jpg返回
    //         that.imgUrl = response.path[0][0].split("|")[1];
    //         // code = that.imgUrl;
    //       }
    //       // that.$emit("changeCode", code, text, that.codeField, that.comType);
    //     })
    //     .catch(err => {
    //       that.modeCode = "";
    //       console.info(err);
    //     });
    // }
  }
};
</script>
<style scoped>
.choosefile {
  float: left;
  text-align: left;
}
</style>
